﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WorkDAL.BranchCode
{
    public class BranchCodeDataAccess
    {
        WorkerDataContext workContext = new WorkerDataContext();

        public static BranchCodeDataAccess Instance()
        {
            return new BranchCodeDataAccess();
        }

        public List<tbBranchCode> BranchCodeGetList()
        {
            var branchCodeList = from c in this.workContext.tbBranchCodes
                           select c;

            return branchCodeList.ToList();
        }

        public List<tbBranchCode> BranchCodeGetList(string branchCode)
        {
            var branchCodeList = from c in this.workContext.tbBranchCodes
                                 where c.BranchCode == branchCode
                                 select c;

            return branchCodeList.ToList();
        }

        public void CreateBranchCode(tbBranchCode branchCode)
        {
            workContext.tbBranchCodes.InsertOnSubmit(branchCode);
            workContext.SubmitChanges();
        }

        public void UpdateBranchCode(tbBranchCode branchCode)
        {
            tbBranchCode branch = workContext.tbBranchCodes.Single(p => p.BranchCode == branchCode.BranchCode);
            branch.AddressEng = branchCode.AddressEng;
            branch.AddressViet = branchCode.AddressViet;
            branch.NameEng = branchCode.NameEng;
            branch.NameViet = branchCode.NameViet;
            branch.PhoneNumber = branchCode.PhoneNumber;
            branch.TaxCode = branchCode.TaxCode;

            workContext.SubmitChanges();
        }
    }

}
